<template>
  <div>
    <a-card class="flex-1" :title="t['门店对接信息']">
      <template #extra>
        <a-button @click="getSassInfo">
          {{ t["查询"] }}
        </a-button>
      </template>
      <div class="flex flex-col gap-2">
        <div>uid: {{ saasData?.uid }}</div>
        <div>sid: {{ saasData?.sid }}</div>
        <div>key: {{ saasData?.key }}</div>
      </div>
    </a-card>
  </div>
</template>

<script setup lang="ts">
import { getUserProfile } from "@/api/service/user";

import { saasInfo } from "@/api/service/user/user";
import { userStore } from "@/store/modules/user/user";
import { getToken } from "@/store/modules/user/utils";

const t = translate("公共模块");

const store = userStore();
const saasData = ref({
  uid: "",
  key: "",
  sid: ""
});
const getSassInfo = async () => {
  const data = await saasInfo();
  saasData.value = data?.data;
};
const form = ref({
  userName: "",
  nickName: "",
  avatar: "",
  userId: ""
});

onMounted(() => {
  if (getToken()) {
    /* Get userInfo */
    getUserProfile().then((res) => {
      const { data } = res;
      form.value.userName = data.user.userName;
      form.value.nickName = data.user.nickName;
      form.value.userId = data.user.userId;
      form.value.avatar = data.user.avatar;
      store.$state.user = data.user;
    });
  }
});
</script>

<style lang="scss" scoped></style>
